package com.tmjx.expression;

import com.tmjx.entitys.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 33117
 * @version 1.0
 * @data 2025/8/24 20:27
 *
 * 自定义权限判断
 */
@Component("ex")
public class SecurityExpressionRoot {

    public boolean hasAuthority(String authoritie){
        // 获取用户权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser principal = (LoginUser) authentication.getPrincipal();
        List<String> permissions = principal.getPermissions();
        // 判断用户权限
        return permissions.contains(authoritie);
    }

}
